//Copyright 2009 Dominik Punz
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

#ifndef dispatchImpl_h__
#define dispatchImpl_h__

#include "resource.h"
#include "SilkTestLib_i.h"
#include "Desktop.h"
#include "jniEnvironment.h"
#include "javaReflection.h"

#include <string>
#include <map>

class CDispatchImpl : public IDispatch
{
public:
  CDispatchImpl() : mRefCount(1)
  { }

  virtual ~CDispatchImpl()
  { }

public:
  // IUnknown implementation
  STDMETHOD(QueryInterface)(const IID& iid, void** ppv) ;
  virtual ULONG __stdcall AddRef() ;
  virtual ULONG __stdcall Release() ;

  //IDispatch implementation
  STDMETHOD(GetTypeInfoCount)(UINT* pctinfo);
  STDMETHOD(GetTypeInfo)(UINT itinfo, 
    LCID lcid, ITypeInfo** pptinfo);
  STDMETHOD(GetIDsOfNames)(REFIID riid, 
    LPOLESTR* rgszNames, UINT cNames,
    LCID lcid, DISPID* rgdispid);
  STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid,
    LCID lcid, WORD wFlags, 
    DISPPARAMS* pdispparams, VARIANT* pvarResult,
    EXCEPINFO* pexcepinfo, UINT* puArgErr);

protected:
  virtual BSTR ToString() = 0;
  virtual HRESULT InvokeDynamicMethod(const std::wstring& strDispName, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) = 0;
  virtual HRESULT GetDynamicProperty(const std::wstring& strDispName, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) = 0;
  virtual HRESULT SetDynamicProperty(const std::wstring& strDispName, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) = 0;

private:
  LONG mRefCount;
};


#endif // dispatchImpl_h__